package br.edu.ufcg.mdaveritas.parser.input;

import java.util.List;

import br.edu.ufcg.mdaveritas.bfs.BFS;
import br.edu.ufcg.mdaveritas.net.Net;
import br.edu.ufcg.mdaveritas.net.Node;
import br.edu.ufcg.mdaveritas.parser.output.EcoreGenerator;

public class Initializer {

	public static void createSubnets(String in, String out) {
		String newline = System.getProperty("line.separator");
		System.out.println(newline + "MDA Veritas - Subnets Initializer" + newline
				+ "---------------------------------");
		PTNetParser p = new PTNetParser();
		System.out.println("Input: " + in);
		long t1 = System.currentTimeMillis();
		Net n = p.getPetriNet(in);
		n = p.initializePreAndPosSet(n);
		BFS bfs = new BFS(n);
		List<Node> subnets = bfs.search();
		System.out.println(newline + "Output: " + out + newline + "---------------------------------"
				+ newline + "Operation completed in "
				+ (System.currentTimeMillis() - t1) + " milliseconds");
		EcoreGenerator egen = new EcoreGenerator(subnets);
		egen.createXML(out);
	}

	public static void main(String[] args) {
		if (args.length == 2) {
			Initializer.createSubnets(args[0], args[1]);
		} else {
			System.out.println("The parameters specified are invalid.");
			System.out
					.println("The correct syntax is: input_file_path output_file_path");
		}
	}
}
